﻿import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    x:500
    y:50
    minimumWidth: 640 //最小
    maximumWidth: 840 //最大
    minimumHeight: 480
    maximumHeight: 740
    //opacity: 0.5 //透明度
    signal mySig()

    //处理信号前面添加on大写一个信号字符
    onMySig: {
        
    }
    /*
    //宽度修改信号
    onWidthChanged: {
        //输出到控制台
        console.log("width changed")
    }
    */

    Button {
        id:btn1
        x:0
        y:0
        width: 50
        height:50
        focus: true
        objectName: "btn1"
        //设置焦点变色
        background: Rectangle {
            border.color: btn1.focus ? "blue" : "black"
        }
        text: qsTr("Click me")
        //设置中心
        //anchors.centerIn: parent
        onClicked: {
            console.log("btn1 clicked")
            mySig()
        }
        //键盘右事件
        Keys.onRightPressed: {
            btn2.focus = true
        }
    }

    Button {
        id:btn2
        x:100
        y:0
        width: 50
        height:50
        objectName: "btn2"
        background: Rectangle {
            border.color: btn2.focus ? "blue" : "black"
        }
        text: qsTr("Click me1")
        //anchors.centerIn: parent
        onClicked: {
            console.log("btn2 clicked")
            mySig()
        }
        //键盘右事件
        Keys.onLeftPressed: {
            btn1.focus = true
        }
    }
    onActiveFocusItemChanged: {
        //焦点变化时输出
        console.log("focus item changed",activeFocusItem,"objectName",activeFocusItem.objectName)
    }
    
    Rectangle {
        x:100
        y:100
        z:1
        width: 100
        height: 100
        color: "red"
        border.color: "black"
        border.width: 5
        radius: 10
        //父对象全填充
        //anchors.fill: parent
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log("rect clicked")
            }
        }
    }
    Rectangle {
        x:120
        y:120
        z:0
        width: 100
        height: 100
        color: "blue"
        border.color: "black"
        border.width: 5
        radius: 10
    }

}
